﻿Imports System.Data.OleDb
Public Class Form1
    Private FClose As Boolean
    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        FClose = True
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Hide()
        'Try
        '    Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True)
        '    key.SetValue("ElecUpdate", Application.ExecutablePath)
        '    key.Close()
        '    key = Nothing
        'Catch ex As Exception
        '    Return
        'End Try
        Dim th As New Threading.Thread(AddressOf Prc)
        th.Start()
        th = Nothing
        Timer1.Interval = 3600000
        Timer1.Enabled = True
        Timer1.Start()
    End Sub
    Private Sub WriteLog(ByVal s As String)
        Try
            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\DFLogs.log", s, True)
        Catch ex As Exception

        End Try

    End Sub
    Private Event aas()

    Private Sub Prc()
        'Try
        '    Dim sqlstr As String = String.Empty
        '    Dim ds As DataSet = Nothing
        '    Dim ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\yfl.mdb; User Id=admin; Password=19770908"
        '    Dim MyConn As New OleDbConnection(ConnStr)
        '    MyConn.Open()
        '    Dim da As OleDbDataAdapter = Nothing
        '    While FClose = False
        '        '--查询所有表名
        '        ds = New DataSet
        '        sqlstr = "select name from MSysObjects where flags=0 and type=1"
        '        da = New OleDbDataAdapter(sqlstr, MyConn)
        '        da.Fill(ds)
        '        Dim ds1 As New DataSet
        '        For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
        '            sqlstr = "select * from " & ds.Tables(0).Rows(i).Item("name")
        '            da = New OleDbDataAdapter(sqlstr, MyConn)
        '            da.Fill(ds1, ds.Tables(0).Rows(i).Item("name"))
        '        Next
        '        '--上传所有数据

        '        Threading.Thread.Sleep(6000)
        '    End While
        'Catch ex As Exception
        '    WriteLog(ex.Message)
        'End Try
        Try
            Dim FName As String = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\n.mdb")
            Dim DBPath As String = Application.StartupPath & "\yfl.mdb"
            Dim FileName As String = Now.ToString("yyyy_MM_dd HH_mm_ss") & ".mdb"
            Dim NPath As String = Application.StartupPath & "\" & FileName
            FServerIP = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\s.mdb")
            IO.File.Copy(DBPath, NPath)
            My.Computer.Network.UploadFile(NPath, "ftp://" & FServerIP & ":21/" & FileName, FName, "f00lkins9")
            WriteLog(String.Format("{0:yyyy-MM-dd HH:mm:ss}:开始上传数据,文件名:{1}", Now, FileName))
            'If SControl._ELEC_UPDATEDB(FName, My.Computer.FileSystem.ReadAllBytes(DBPath)) = False Then
            'WriteLog(Now.ToString("yyyy-MM-dd HH:mm:ss") & "上传数据失败!")
            'End If
        Catch ex As Exception
            WriteLog(String.Format("{0:yyyy-MM-dd HH:mm:ss}:上传数据出错,原因:{1}", Now, ex.Message))
            Return
        End Try
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim th As New Threading.Thread(AddressOf Prc)
        th.Start()
        th = Nothing
    End Sub
End Class
